#include <iostream>
using namespace std;

#include "DataStream.h"
#include "DataStream_xml.h"
#include "Serializable.h"
#include "Serializable_xml.h"

using namespace Serialize;
using namespace Serialize_xml;

class A : public Serializable
{
private:
    string m_name;
    int m_age;
    double m_height;
    string m_gender;
    vector<double> m_score;
public:
    A(){}
    A(const string &name, int age, const string &gender, double height):m_name(name), m_age(age), m_gender(gender), m_height(height)
    {
        for(int i = 0; i < 3; i++)
        {
            m_score.push_back(i * 10);
        }
    }
    ~A(){}

    void show()
    {
        cout << "Name: " << m_name << endl;
        cout << "Age: " << m_age << endl;
        cout << "Gender: " << m_gender << endl;
        cout << "Height: " << m_height << endl;
        cout << "Scores:";
        for (int i = 0; i < 3; i++)
        {
            cout << m_score[i] << endl;
        }
    }

    SERIALIZE(m_name, m_age, m_gender, m_height, m_score);
};

class A_xml : public Serializable_xml
{
private:
    string m_name;
    int m_age;
    double m_height;
    string m_gender;

public:
    A_xml(){}
    A_xml(const string &name, int age, const string &gender, double height):m_name(name), m_age(age), m_gender(gender), m_height(height){}
    ~A_xml(){}

    void show()
    {
        cout << "Name: " << m_name << endl;
        cout << "Age: " << m_age << endl;
        cout << "Gender: " << m_gender << endl;
        cout << "Height: " << m_height << endl;
    }

    SERIALIZE_XML(m_name, m_age, m_gender, m_height);
};

int main()
{
    A a("kitty", 18, "male", 1.8);

    cout << "------------------------------Test Binary-----------------------------------" << endl;
    cout << "-----------------------Origin class-------------------------" << endl;
    a.show();
    DataStream ds;
    serialize(a, "example.data");
    A b;
    deserialize(b, "example.data");
    cout << "-----------------------Deserialize class-------------------------" << endl;
    b.show();

    cout << "------------------------------Test xml-----------------------------------" << endl;
    A_xml aa("kitty", 18, "male", 1.8);
    cout << "-----------------------Origin class-------------------------" << endl;
    aa.show();
    serialize_xml(aa, "object", "example_xml.xml");
    A_xml bb;
    deserialize_xml(bb, "object", "example_xml.xml");
    cout << "-----------------------Deserialize class-------------------------" << endl;
    bb.show();
    cout << "------------------------------Test pair-----------------------------------" << endl;
    std::pair<int, double> pair0 = {2, 3.1}, pair1;
    serialize_xml(pair0, "std_pair", "data.xml");
    deserialize_xml(pair1, "std_pair", "data.xml");
    cout << "pair0 = {" << pair0.first << "," << pair0.second << "}" << endl;
    cout << "pair1 = {" << pair1.first << "," << pair1.second << "}" << endl;

    return 0;
}